import * as THREE from 'three';

class Container {
    constructor() {}

    destory() {
        // console.warn('Container.destory: ', typeof this.modelsGroup, this.modelsGroup instanceof THREE.Group);
        console.warn('Container.destory: ', this);
        Object.keys(this).forEach(k => {
            // console.warn('Container.destory: ', k);
            if (this[k] instanceof THREE.Scene) {
                for (let i = 0, len = this[k].children.length; i < len; i++) {
                    this.deleteGroup(this[k].children[i]);
                    this[k].remove(this[k].children[i]);
                }
            } else if (this[k] instanceof THREE.Group) {
                this.deleteGroup(this[k]);
                // delete this[k];
            }
            // delete this[k];
        });
    }

    deleteGroup(group) {
        if (!group || !(group instanceof THREE.Group)) return;
        // console.warn('Base.deleteGroup: ', group);
        group.traverse(function (item) { //eslint-disable-line
            if (item instanceof THREE.Mesh) {
                item.geometry.dispose(); // 删除几何体
                item.material.dispose(); // 删除材质
            }
        });
    }
}

export default Container;
